/**
  ******************************************************************************
  * @file    Project/STM32F4xx_StdPeriph_Templates/main.c 
  * @author  MCD Application Team
  * @version V1.8.1
  * @date    27-January-2022
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2016 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usb_core.h"
#include "usbh_msc_core.h"
#include "usbh_usr.h"
#include "fatfs.h"
#include "bootloader.h"
#include <stdio.h>
#include "ff.h"

__IO uint32_t uwTick;

USB_OTG_CORE_HANDLE  USB_OTG_Core;
USBH_HOST  USB_Host;

extern ApplicationTypeDef Appli_state;

void FLASH_If_Init(void)
{ 
  FLASH_Unlock(); // �����ڲ�Flash

  /* Clear pending flags (if any) */  
	FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |FLASH_FLAG_WRPERR |FLASH_FLAG_PGAERR |FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR | FLASH_FLAG_BSY| FLASH_FLAG_RDERR);

}


/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    FLASH_If_Init();
    USBH_Init(&USB_OTG_Core,USB_OTG_FS_CORE_ID,&USB_Host,&USBH_MSC_cb,&USR_cb_Host);  
    FATFS_INIT();
		
    /* Infinite loop */
    while (1)
    {
				if(Appli_state == APPLICATION_READY)
				{
            udisk_update();
				}
				else
				{
            USBH_Process(&USB_OTG_Core, &USB_Host);
				}
				
    }
}

__weak void HAL_IncTick(void)
{
  uwTick += 1;
}

/**
  * @brief Provides a tick value in millisecond.
  * @note This function is declared as __weak to be overwritten in case of other 
  *       implementations in user file.
  * @retval tick value
  */
__weak uint32_t HAL_GetTick(void)
{
  return uwTick;
}


#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/**
  * @}
  */


